package cn.butcher21.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * butcher create in 2021/04/26/22:35
 */
@WebServlet("/last")
public class LastProject extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies();
        String projectNum = "1";
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("project")) {
                    projectNum = cookie.getValue();
                    break;
                }
            }
        }
        PrintWriter out = response.getWriter();
        out.print(projectNum);
        out.flush();
        out.close();
    }
}
